<?php 
namespace app\admin\controller;
use \think\Controller;
/**
*论坛管理
*/
class Forum extends Base{
	public function brief(){
		$model=model("TkPost");
		$status=$model->paginate("5",false);
		$page=$status->render();
		if(count($status)!=0){
			foreach ($status as $k => $v) {
			$data[]=$v->toArray();
			}
			//遍历处理展示的信息 帖子标题,内容,发帖人,发帖时间
			foreach ($data as $k => $v) {

				$title[]=$v['post_title'];
				$content[]=$v['post_content'];
				$mid[]=$v['user_id'];
				$time[]=$v['ptime'];
			}
			$mid=implode(",",$mid);
			$state=model("TkFrontUser");
			$result=$state->where(['mid'=>['in',$mid]])->field("uname")->select();
			foreach ($result as $k => $v) {
				$res[]=$v->toArray();
			}
			foreach ($res as $k => $v) {
				$uname[]=$res[$k]['uname'];
			}		
			if(!isset($_GET['page'])){
				$_GET['page']=1;
			}
			$num=count($status);
			$pagenum=ceil($num/5);
			$nowpage=$_GET['page'];
			$list=(($nowpage-1)*5)+1;
			$num=$status->count();
			$this->assign("a",1);
			$this->assign("num",$num);
			$this->assign("pagenum",$pagenum);
			$this->assign("title",$title);
			$this->assign("content",$content);
			$this->assign("time",$time);
			$this->assign("uname",$uname);
			$this->assign("list",$list);
			$this->assign("page",$page);
			return $this->fetch();
		}else{
			$a=2;
			$this->assign("a",$a);
			return $this->fetch();
		}
		
	}
	public function response(){
		$model=model("TkResponse");
		$tk=$model->alias('t')->join("tk_post k","k.id=t.post_id","left")->join("tk_front_user u","u.mid=t.user_id","left")->field("t.res_content content,t.res_time time,k.post_title title,u.uname uname")->paginate("5",false);
		$num=count($tk);
		$page=$tk->render();
		if($num!=0){
			foreach ($tk as $k=>$v) {
			 	$status[]=$v->toArray();
			}
			foreach ($status as $k => $v) {
				$content[]=$v['content'];
				$time[]=$v['time'];
				$title[]=$v['title'];
				$uname[]=$v['uname'];
			}
			$a=1;
			if(!isset($_GET['page'])){
				$_GET['page']=1;
			}
			$nowpage=$_GET['page'];
			$list=(($nowpage-1)*5)+1;
			$pagenum=ceil($num/5);
			$this->assign("a",$a);
			$this->assign("list",$list);
			$this->assign("content",$content);
			$this->assign("time",$time);
			$this->assign("title",$title);
			$this->assign("uname",$uname);
			$this->assign("pagenum",$pagenum);
			$this->assign("num",$num);
			$this->assign("page",$page);
			return $this->fetch();
		}else{
			$a=2;
			$this->assign("a",$a);
			return $this->fetch();
		}
	}
}